package com.ruoyi.member.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.member.api.domain.UmsMember;
import com.ruoyi.member.service.IUmsMemberService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 会员Controller
 * 
 * @author LEE
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/member")
public class UmsMemberController extends BaseController {
	@Autowired
	private IUmsMemberService umsMemberService;

	/**
	 * 查询会员列表
	 */
	@PreAuthorize(hasPermi = "member:member:list")
	@GetMapping("/list")
	public TableDataInfo list(UmsMember umsMember) {
		startPage();
		List<UmsMember> list = umsMemberService.selectUmsMemberList(umsMember);
		return getDataTable(list);
	}

	/**
	 * 导出会员列表
	 */
	@PreAuthorize(hasPermi = "member:member:export")
	@Log(title = "会员", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, UmsMember umsMember) throws IOException {
		List<UmsMember> list = umsMemberService.selectUmsMemberList(umsMember);
		ExcelUtil<UmsMember> util = new ExcelUtil<UmsMember>(UmsMember.class);
		util.exportExcel(response, list, "会员数据");
	}

	/**
	 * 获取会员详细信息
	 */
	@PreAuthorize(hasPermi = "member:member:query")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(umsMemberService.selectUmsMemberById(id));
	}

	/**
	 * 新增会员
	 */
	@PreAuthorize(hasPermi = "member:member:add")
	@Log(title = "会员", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody UmsMember umsMember) {
		return toAjax(umsMemberService.insertUmsMember(umsMember));
	}

	/**
	 * 修改会员
	 */
	@PreAuthorize(hasPermi = "member:member:edit")
	@Log(title = "会员", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody UmsMember umsMember) {
		return toAjax(umsMemberService.updateUmsMember(umsMember));
	}

	/**
	 * 删除会员
	 */
	@PreAuthorize(hasPermi = "member:member:remove")
	@Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(umsMemberService.deleteUmsMemberByIds(ids));
	}
}
